package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.StudentState;
import cn.wolfcode.crm.query.StudentStateQueryObject;
import cn.wolfcode.crm.service.IOfficialstuService;
import cn.wolfcode.crm.service.IStudentStateService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("studentState")
public class StudentStateController {

    @Autowired
    private IStudentStateService service;
    @Autowired
    private IOfficialstuService officialstuService;

    @PermissionName("学员班级转换首页")
    @RequiresPermissions("studentState:index")
    @RequestMapping("index")
    public String index(){
        return "studentState/list";
    }

    @PermissionName("学员班级转换列表")
    @RequiresPermissions("studentState:list")
    @ResponseBody
    @RequestMapping("list")
    public PageResult list(StudentStateQueryObject qo){
        PageResult result = service.query(qo);
        return result;
    }

    @PermissionName("学员班级转换保存")
    @RequiresPermissions("studentState:save")
    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(StudentState studentState){
        try{
            service.save(studentState);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("转班失败");
        }
        return new JsonResult();
    }

    @PermissionName("学员班级转换审核")
    @RequiresPermissions("studentState:checkState")
    @ResponseBody
    @RequestMapping("checkState")
    public JsonResult checkState(Long id){
        try{
            service.checkState(id);
        }catch (Exception e){
            e.printStackTrace();
            new JsonResult("审核失败");
        }
        return new JsonResult();
    }

}
